package by.bsu.android.lab.chrono;


public class ChronoActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);

	final Button buttonStart = (Button) findViewById(R.id.button_start);
	final Button buttonStop = (Button) findViewById(R.id.button_stop);
	final Button buttonReset = (Button) findViewById(R.id.button_reset);
	final Chronometer mChronometer = (Chronometer) findViewById(R.id.chronometer);

	buttonStart.setOnClickListener(new OnClickListener() {

	    public void onClick(View v) {

		mChronometer.start();
	    }
	});

	buttonStop.setOnClickListener(new OnClickListener() {

	    public void onClick(View v) {

		mChronometer.stop();
	    }
	});

	buttonReset.setOnClickListener(new OnClickListener() {

	    public void onClick(View v) {

		mChronometer.setBase(SystemClock.elapsedRealtime());
	    }
	});

	String ns = Context.NOTIFICATION_SERVICE;
	NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

	int icon = R.drawable.notification_icon;
	CharSequence tickerText = "Chronometer";
	long when = System.currentTimeMillis();
	Context context = getApplicationContext();
	CharSequence contentTitle = "Chronometer notification";
	CharSequence contentText = "Chronometer is working...";

	Intent notificationIntent = new Intent(this, ChronoActivity.class);
	PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

	Notification notification = new Notification(icon, tickerText, when);
	notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

	mNotificationManager.notify(1, notification);

    }
}